#include "client.h"
#include <stdio.h>

int main()
{
    int clientfd = tcpConnect("192.168.220.129", 8080);
    
    int flag = 0;
    while(1){
        printf("1.login 2.register\n");
        scanf("%d", &flag);
        if(flag == 1 || flag == 2) break;
    }
    if(flag == 1){
        //登录验证
        loginFunc(clientfd);
    } else{
        //注册操作
        registerFunc(clientfd);
    }

    char buf[128] = {0};
    train_t t;

    while(1) {
        //读取标准输入中的数据
        memset(buf, 0, sizeof(buf));
        int ret = read(STDIN_FILENO, buf, sizeof(buf));
        if(0 == ret) {
            printf("byebye.\n");
            break;
        }
        //fgets(buf, sizeof(buf), stdin); 
        //buf[strlen(buf) - 1] = '\0';
        memset(&t, 0, sizeof(t));
        //解析命令行
        buf[strlen(buf)-1] = '\0';
        parseCommand(buf, strlen(buf) - 1, &t);
        //处理命令
        commandHandler(clientfd, &t);
    }
    close(clientfd);
    return 0;
}

